<template>
  <div>
    <!-- 顶部组件 -->
    <header-nav></header-nav>
    <van-index-bar :index-list="leftList">
      <div v-for="(item, index) in rightList" :key="index" >
        <van-index-anchor :index="item.name" />
        <van-cell v-for="(value,i) in item.data" :key="value.id" v-show="i<10">
          <!-- 使用 title 插槽来自定义标题 -->
          <template #title>
            <!-- <div class="van-cell-title"> -->
            <router-link tag="div" class="van-cell-title" :to="'/singer/singerlist?id='+value.id">
              <img width="45" height="45" v-lazy="value.img1v1Url" />
              <span class="custom-title">{{ value.name }}</span>
            </router-link>
            <!-- </div> -->
          </template>
        </van-cell>
      </div>
    </van-index-bar>
  </div>
</template>

<script>
import { getArtistlist } from "../api/singer";
import headerNav from "../components/base/headerNav.vue";
export default {
  components: {
    headerNav,
  },
  data() {
    return {
      leftList: [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "N",
        "M",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
      ],
      rightList: [],
    };
  },
  methods: {
    ArtistListFun() {
      for (let i = 0; i < this.leftList.length; i++) {
        this.rightList.push({
          name: this.leftList[i],
        });
      }
      // console.log(this.rightList);
    },
  },
  created() {
    this.ArtistListFun();

    for (let i = 0; i < this.leftList.length; i++) {
      getArtistlist({
        type: 1,
        area: 96,
        initial: this.leftList[i],
      }).then((data) => {
        let index = this.rightList.findIndex(
          (item) => item.name == this.leftList[i]
        );
        this.$set(this.rightList[index], "data", data.artists);
      });
    }
  },
};
</script>

<style lang="less">
.van-cell-title {
  display: flex;
  align-items: center;
  span {
    color: #666;
    margin-left: 20px;
  }
}
.van-index-anchor {
  background-color: #d9dadb;
}
</style>